package jscinttools.utilities.jhplotutilities;
import java.lang.String;
import java.lang.StringBuffer;
import java.lang.Double;
import java.text.DecimalFormat;
import java.awt.FontMetrics;
import java.awt.Font;
import java.awt.Color;
import jhplot.HPlotJa;
import jhplot.jadraw.JaAxes;
import jhplot.jadraw.JaText;
import jplot.Translate;
import japlot.Global;
/**
 *  Description of the Class
 *
 *@author     Marc-Antoine Verdier
 *@created    13 juin 2011
 */
public class HPlotJaBeautifier implements PlotterBeautifier
{
	private HPlotJa plotter;
	private int numPadX;
	private int numPadY;
	private JaAxes[][] axes;
	private double[][] widthNDCX;
	private double[][] heightNDCX;
	private double[][] widthNDCY;
	private double[][] heightNDCY;
	private JaText[][] axisLabelX;
	private JaText[][] axisLabelY;


	/**
	 *  Constructor for the HPlotJaBeautifier object
	 *
	 *@param  plotter  The HPlotJa to improve
	 */
	public HPlotJaBeautifier(HPlotJa plotter)
	{
		this.plotter = plotter;
		this.numPadX = plotter.getNtotX();
		this.numPadY = plotter.getNtotY();
		this.axes = new JaAxes[numPadX][numPadY];
		this.widthNDCX = new double[numPadX][numPadY];
		this.heightNDCX = new double[numPadX][numPadY];
		this.widthNDCY = new double[numPadX][numPadY];
		this.heightNDCY = new double[numPadX][numPadY];
		this.axisLabelX = new JaText[numPadX][numPadY];
		this.axisLabelY = new JaText[numPadX][numPadY];
	}


	/**
	 *  refresh the axes component with the current plotter values
	 */
	private void initializeAxes()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				plotter.cd(i + 1, j + 1);
				this.axes[i][j] = plotter.getPad();
			}
		}
	}


	private void initializeAxisLabelX()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				this.axisLabelX[i][j] = plotter.getLabelX()[i][j];
				this.widthNDCX[i][j] = calcLabelHeight(axisLabelX[i][j]);
				this.heightNDCX[i][j] = calcLabelWidth(axisLabelX[i][j]);
			}
		}
	}


	private void initializeAxisLabelY()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				this.axisLabelY[i][j] = plotter.getLabelY()[i][j];
				this.widthNDCY[i][j] = calcLabelHeight(axisLabelY[i][j]);
				this.heightNDCY[i][j] = calcLabelWidth(axisLabelY[i][j]);
			}
		}
	}


	/**
	 *  Use the font for the X axis label of the pad
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 *@param  font  The Font to use
	 */
	public void useAxisLabelFontX(int padX, int padY, Font font)
	{
		initializeAxisLabelX();
		axisLabelX[padX - 1][padY - 1].setFont(font);
	}


	/**
	 *  Use the font for the X axis label on all the pads
	 *
	 *@param  font  The Font to use
	 */
	public void useAxisLabelFontX(Font font)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				useAxisLabelFontX(i + 1, j + 1, font);
			}
		}
	}


	/**
	 *  Use the font for the Y axis label of the pad
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 *@param  font  The Font to use
	 */
	public void useAxisLabelFontY(int padX, int padY, Font font)
	{
		initializeAxisLabelY();
		axisLabelY[padX - 1][padY - 1].setFont(font);
	}


	/**
	 *  Use the font for the Y axis label on all the pads
	 *
	 *@param  font  The Font to use
	 */
	public void useAxisLabelFontY(Font font)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				useAxisLabelFontY(i + 1, j + 1, font);
			}
		}
	}


	/**
	 *  Use the color for the X axis label of the pad
	 *
	 *@param  padX   X coordinate of the pad
	 *@param  padY   Y coordinate of the pad
	 *@param  color  The Color to use
	 */
	public void useAxisLabelColorX(int padX, int padY, Color color)
	{
		initializeAxisLabelX();
		axisLabelX[padX - 1][padY - 1].setColor(color);
	}


	/**
	 *  Use the color for the X axis label on all the pads
	 *
	 *@param  color  The Color to use
	 */
	public void useAxisLabelColorX(Color color)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				useAxisLabelColorX(i + 1, j + 1, color);
			}
		}
	}


	/**
	 *  Use the color for the Y axis label of the pad
	 *
	 *@param  padX   X coordinate of the pad
	 *@param  padY   Y coordinate of the pad
	 *@param  color  The Color to use
	 */
	public void useAxisLabelColorY(int padX, int padY, Color color)
	{
		initializeAxisLabelY();
		axisLabelY[padX - 1][padY - 1].setColor(color);
	}


	/**
	 *  Use the color for the Y axis label on all the pads
	 *
	 *@param  color  The Color to use
	 */
	public void useAxisLabelColorY(Color color)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				useAxisLabelColorY(i + 1, j + 1, color);
			}
		}
	}


	/**
	 *  Description of the Method
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 *@param  axis  Description of the Parameter
	 */
	private void removeMinusSymbolOnZero(int padX, int padY, int axis)
	{
		initializeAxes();
		String[][] tLab = axes[padX - 1][padY - 1].getTicLabel();
		for (int i = 0; i < tLab[axis].length; i++)
		{
			if (tLab[axis][i].equals("-0"))
				tLab[axis][i] = "0";

			if (tLab[axis][i].equals("-0.0"))
				tLab[axis][i] = "0.0";

			if (tLab[axis][i].equals("-0.00"))
				tLab[axis][i] = "0.00";
		}
		axes[padX - 1][padY - 1].setTicLabel(tLab);
	}


	/**
	 *  Removes the "-" symbol that sometime appears in front of "0" for the X axis
	 *  of the pad
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 */
	public void removeMinusSymbolOnZeroX(int padX, int padY)
	{
		removeMinusSymbolOnZero(padX, padY, 0);
	}


	/**
	 *  Removes the "-" symbol that sometime appears in front of "0" for the X axis
	 *  for all the pads
	 */
	public void removeMinusSymbolOnZeroX()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				removeMinusSymbolOnZeroX(i + 1, j + 1);
			}
		}
	}


	/**
	 *  Removes the "-" symbol that sometime appears in front of "0" for the Y axis
	 *  of the pad
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 */
	public void removeMinusSymbolOnZeroY(int padX, int padY)
	{
		removeMinusSymbolOnZero(padX, padY, 1);
	}


	/**
	 *  Removes the "-" symbol that sometime appears in front of "0" for the Y axis
	 *  for all the pads
	 */
	public void removeMinusSymbolOnZeroY()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				removeMinusSymbolOnZeroY(i + 1, j + 1);
			}
		}
	}


	/**
	 *  Description of the Method
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 *@param  axis  Description of the Parameter
	 */
	private void displayTickLabelAsTenPower(int padX, int padY, int axis)
	{
		initializeAxes();
		String[][] tLab = axes[padX - 1][padY - 1].getTicLabel();
		for (int i = 0; i < tLab[axis].length; i++)
		{
			if (tLab[axis][i].equals("1") || tLab[axis][i].equals("1.0") || tLab[axis][i].equals("1.00"))
				tLab[axis][i] = "10^{0}";

			if (tLab[axis][i].equals("10"))
				tLab[axis][i] = "10^{1}";
		}
		axes[padX - 1][padY - 1].setTicLabel(tLab);
	}


	/**
	 *  Display "1" as "10^0" and "10" as "10^1" for the X axis tick label of the
	 *  pad
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 */
	public void displayTickLabelAsTenPowerX(int padX, int padY)
	{
		displayTickLabelAsTenPower(padX, padY, 0);
	}


	/**
	 *  Display "1" as "10^0" and "10" as "10^1" for the X axis tick label of all
	 *  the pads
	 */
	public void displayTickLabelAsTenPowerX()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				displayTickLabelAsTenPowerX(i + 1, j + 1);
			}
		}
	}


	/**
	 *  Display "1" as "10^0" and "10" as "10^1" for the Y axis tick label of the
	 *  pad
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 */
	public void displayTickLabelAsTenPowerY(int padX, int padY)
	{
		displayTickLabelAsTenPower(padX, padY, 1);
	}


	/**
	 *  Display "1" as "10^0" and "10" as "10^1" for the Y axis tick label of all
	 *  the pads
	 */
	public void displayTickLabelAsTenPowerY()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				displayTickLabelAsTenPowerY(i + 1, j + 1);
			}
		}
	}


	/**
	 *  Description of the Method
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 *@param  axis  Description of the Parameter
	 */
	private void removeTickLabel(int padX, int padY, int axis)
	{
		initializeAxes();
		String[][] tLab = axes[padX - 1][padY - 1].getTicLabel();
		for (int i = 0; i < tLab[axis].length; i++)
		{
			tLab[axis][i] = "";
		}
		axes[padX - 1][padY - 1].setTicLabel(tLab);
	}


	/**
	 *  Remove all the X axis tick label of the pad
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 */
	public void removeTickLabelX(int padX, int padY)
	{
		removeTickLabel(padX, padY, 0);
	}


	/**
	 *  Remove all the X axis tick label of all the pads
	 */
	public void removeTickLabelX()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				removeTickLabelX(i + 1, j + 1);
			}
		}
	}


	/**
	 *  Remove all the Y axis tick label of the pad
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 */
	public void removeTickLabelY(int padX, int padY)
	{
		removeTickLabel(padX, padY, 1);
	}


	/**
	 *  Remove all the Y axis tick label of all the pads
	 */
	public void removeTickLabelY()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				removeTickLabelY(i + 1, j + 1);
			}
		}
	}


	//private void displayAxisLabelAtCenterX(int padX, int padY, double axisDistNDC, double widthNDC, double heightNDC)
	//{
	//	initializeAxisLabelX();
	//	double xPos = 0.5 - 0.5 * widthNDC;
	//	double yPos = 1 - axisDistNDC;
	//	axisLabelX[padX - 1][padY - 1].setLocation(xPos, yPos, "NDC");
	//}


	/**
	 *  Display the label of the X axis at the center of the pad and at the given
	 *  distance of the axis (Doesn't work yet if there is more than one pad)
	 *
	 *@param  padX         X coordinate of the pad
	 *@param  padY         Y coordinate of the pad
	 *@param  axisDistNDC  The distance from the X axis in NDC coordinate
	 */
	public void displayAxisLabelAtCenterX(int padX, int padY, double axisDistNDC)
	{
		//double heightNDC = calcLabelHeight(axisLabelX[padX - 1][padY - 1]);
		//double widthNDC = calcLabelWidth(axisLabelX[padX - 1][padY - 1]);
		//displayAxisLabelAtCenterX(padX, padY, axisDistNDC, widthNDC, heightNDC);

		initializeAxisLabelX();
		double xPos = 0.5 - 0.5 * widthNDCX[padX - 1][padY - 1];
		double yPos = 1 - axisDistNDC;
		axisLabelX[padX - 1][padY - 1].setLocation(xPos, yPos, "NDC");
	}


	/**
	 *  Display the label of the X axis at the center of the pad (Doesn't work yet
	 *  if there is more than one pad)
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 */
	public void displayAxisLabelAtCenterX(int padX, int padY)
	{
		//double heightNDC = calcLabelHeight(axisLabelX[padX - 1][padY - 1]);
		//double widthNDC = calcLabelWidth(axisLabelX[padX - 1][padY - 1]);
		//double axisDistNDC = (plotter.getMarginBottom() - heightNDC) * plotter.getSizeX() / plotter.getSizeY() / 2.0;
		//displayAxisLabelAtCenterX(padX, padY, axisDistNDC, widthNDC, heightNDC);
		double axisDistNDC = (plotter.getMarginBottom() - heightNDCX[padX - 1][padY - 1]) * plotter.getSizeX() / plotter.getSizeY() / 2.0;
		displayAxisLabelAtCenterX(padX, padY, axisDistNDC);
	}


	/**
	 *  Display the label of the X axis at the center of the pad for all of them
	 *  and at the given distance of their axis (Doesn't work yet if there is more
	 *  than one pad)
	 *
	 *@param  axisDistNDC  The distance from the X axis in NDC coordinate
	 */
	public void displayAxisLabelAtCenterX(double axisDistNDC)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				displayAxisLabelAtCenterX(i + 1, j + 1, axisDistNDC);
			}
		}
	}


	/**
	 *  Display the label of the X axis at the center of the pad for all of them
	 *  (Doesn't work yet if there is more than one pad)
	 */
	public void displayAxisLabelAtCenterX()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				displayAxisLabelAtCenterX(i + 1, j + 1);
			}
		}
	}


	//private void displayAxisLabelAtCenterY(int padX, int padY, double axisDistNDC, double widthNDC, double heightNDC)
	//{
	//	initializeAxisLabelY();
	//	double xPos = axisDist + heightNDC;
	//	double yPos = 0.5 + (0.5 * widthNDC * plotter.getSizeX() / plotter.getSizeY());
	//	axisLabelY[padX - 1][padY - 1].setLocation(xPos, yPos, "NDC");
	//}


	/**
	 *  Display the label of the Y axis at the center of the pad and at the given
	 *  distance of the axis (Doesn't work yet if there is more than one pad)
	 *
	 *@param  padX         X coordinate of the pad
	 *@param  padY         Y coordinate of the pad
	 *@param  axisDistNDC  The distance from the Y axis in NDC coordinate
	 */
	public void displayAxisLabelAtCenterY(int padX, int padY, double axisDistNDC)
	{
		//double heightNDC = calcLabelHeight(axisLabelY[padX - 1][padY - 1]);
		//double widthNDC = calcLabelWidth(axisLabelY[padX - 1][padY - 1]);
		//displayAxisLabelAtCenterY(padX, padY, axisDistNDC, widthNDC, heightNDC);

		initializeAxisLabelX();
		double xPos = axisDistNDC + heightNDCY[padX - 1][padY - 1];
		double yPos = 0.5 + (0.5 * widthNDCY[padX - 1][padY - 1] * plotter.getSizeX() / plotter.getSizeY());
		axisLabelY[padX - 1][padY - 1].setLocation(xPos, yPos, "NDC");
	}


	/**
	 *  Display the label of the Y axis at the center of the pad (Doesn't work yet
	 *  if there is more than one pad)
	 *
	 *@param  padX  X coordinate of the pad
	 *@param  padY  Y coordinate of the pad
	 */
	public void displayAxisLabelAtCenterY(int padX, int padY)
	{
		//double heightNDC = calcLabelHeight(axisLabelY[padX - 1][padY - 1]);
		//double widthNDC = calcLabelWidth(axisLabelY[padX - 1][padY - 1]);
		//double axisDistNDC = ((plotter.getMarginLeft() / 2.0) - heightNDC) * plotter.getSizeY() / plotter.getSizeX();
		//displayAxisLabelAtCenterY(padX, padY, axisDistNDC);

		double axisDistNDC = ((plotter.getMarginLeft() / 2.0) - heightNDCY[padX - 1][padY - 1]) * plotter.getSizeY() / plotter.getSizeX();
		displayAxisLabelAtCenterY(padX, padY, axisDistNDC);
	}


	/**
	 *  Display the label of the Y axis at the center of the pad for all of them
	 *  and at the given distance of their axis (Doesn't work yet if there is more
	 *  than one pad)
	 *
	 *@param  axisDistNDC  The distance from the Y axis in NDC coordinate
	 */
	public void displayAxisLabelAtCenterY(double axisDistNDC)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				displayAxisLabelAtCenterY(i + 1, j + 1, axisDistNDC);
			}
		}
	}


	/**
	 *  Display the label of the Y axis at the center of the pad for all of them
	 *  (Doesn't work yet if there is more than one pad)
	 */
	public void displayAxisLabelAtCenterY()
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				displayAxisLabelAtCenterY(i + 1, j + 1);
			}
		}
	}


	///**
	// *  Description of the Method
	// *
	// *@param  padX       Description of the Parameter
	// *@param  padY       Description of the Parameter
	// *@param  axis       Description of the Parameter
	// *@param  axisDist   Description of the Parameter
	// *@param  widthNDC   Description of the Parameter
	// *@param  heightNDC  Description of the Parameter
	// */
	//private void displayAxisLabelAtCenter(int padX, int padY, int axis, double axisDist, double widthNDC, double heightNDC)
	//{
	//	double xPos = 0.0;
	//	double yPos = 0.0;
	//	if (axis == 0)
	//	{
	//		xPos = 0.5 - 0.5 * widthNDC;
	//		yPos = 1 - axisDist;
	//		axisLabelX[padX - 1][padY - 1].setLocation(xPos, yPos, "NDC");
	//	}
	//	else if (axis == 1)
	//	{
	//		xPos = axisDist + heightNDC;
	//		yPos = 0.5 + 0.5 * widthNDC * plotter.getSizeX() / plotter.getSizeY();
	//		axisLabelY[padX - 1][padY - 1].setLocation(xPos, yPos, "NDC");
	//	}
	//	else
	//		System.out.println("Wrong Axis !!!");
	//}
	//
	//
	///**
	// *  Description of the Method
	// *
	// *@param  padX      Description of the Parameter
	// *@param  padY      Description of the Parameter
	// *@param  axis      Description of the Parameter
	// *@param  axisDist  Description of the Parameter
	// */
	//public void displayAxisLabelAtCenter(int padX, int padY, int axis, double axisDist)
	//{
	//	initializeAxisLabel(axis);
	//	double heightNDC = 0.0;
	//	double widthNDC = 0.0;
	//	if (axis == 0)
	//	{
	//		heightNDC = calcLabelHeight(axisLabelX[padX - 1][padY - 1]);
	//		widthNDC = calcLabelWidth(axisLabelX[padX - 1][padY - 1]);
	//	}
	//	else if (axis == 1)
	//	{
	//		widthNDC = calcLabelWidth(axisLabelY[padX - 1][padY - 1]);
	//		heightNDC = calcLabelHeight(axisLabelY[padX - 1][padY - 1]);
	//	}
	//	else
	//		System.out.println("Wrong Axis !!!");
	//
	//	displayAxisLabelAtCenter(padX, padY, axis, axisDist, widthNDC, heightNDC);
	//}
	//
	//
	///**
	// *  Description of the Method
	// *
	// *@param  axis      Description of the Parameter
	// *@param  axisDist  Description of the Parameter
	// */
	//public void displayAxisLabelAtCenter(int axis, double axisDist)
	//{
	//	for (int i = 0; i < numPadX; i++)
	//	{
	//		for (int j = 0; j < numPadY; j++)
	//		{
	//			displayAxisLabelAtCenter(i + 1, j + 1, axis, axisDist);
	//		}
	//	}
	//}
	//
	//
	///**
	// *  Description of the Method
	// *
	// *@param  padX  Description of the Parameter
	// *@param  padY  Description of the Parameter
	// *@param  axis  Description of the Parameter
	// */
	//public void displayAxisLabelAtCenter(int padX, int padY, int axis)
	//{
	//	initializeAxisLabel(axis);
	//	double heightNDC = 0.0;
	//	double widthNDC = 0.0;
	//	double axisDist = 0.0;
	//	if (axis == 0)
	//	{
	//		heightNDC = calcLabelHeight(axisLabelX[padX - 1][padY - 1]);
	//		widthNDC = calcLabelWidth(axisLabelX[padX - 1][padY - 1]);
	//		axisDist = (plotter.getMarginBottom() - heightNDC) * plotter.getSizeX() / plotter.getSizeY() / 2.0;
	//	}
	//	else if (axis == 1)
	//	{
	//		widthNDC = calcLabelWidth(axisLabelY[padX - 1][padY - 1]);
	//		heightNDC = calcLabelHeight(axisLabelY[padX - 1][padY - 1]);
	//		axisDist = ((plotter.getMarginLeft() / 2.0) - heightNDC) * plotter.getSizeY() / plotter.getSizeX();
	//	}
	//	else
	//		System.out.println("Wrong Axis !!!");
	//
	//	displayAxisLabelAtCenter(padX, padY, axis, axisDist, widthNDC, heightNDC);
	//}
	//
	//
	///**
	// *  Description of the Method
	// *
	// *@param  axis  Description of the Parameter
	// */
	//public void displayAxisLabelAtCenter(int axis)
	//{
	//	for (int i = 0; i < numPadX; i++)
	//	{
	//		for (int j = 0; j < numPadY; j++)
	//		{
	//			displayAxisLabelAtCenter(i + 1, j + 1, axis);
	//		}
	//	}
	//}


	/**
	 *  Calculates the width of the label in NDC coordinates
	 *
	 *@param  label  Description of the Parameter
	 *@return        Description of the Return Value
	 */
	private double calcLabelWidth(JaText label)
	{
		FontMetrics fm = calcFontMetrics(label);
		String stext = Translate.shrink(label.getText());
		int width = fm.stringWidth(stext);
		return Global.toX(width);
	}


	/**
	 *  Calculates the height of the label in NDC coordinates
	 *
	 *@param  label  Description of the Parameter
	 *@return        Description of the Return Value
	 */
	private double calcLabelHeight(JaText label)
	{
		FontMetrics fm = calcFontMetrics(label);
		int height = fm.getHeight();
		return Global.toY(height);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  label  Description of the Parameter
	 *@return        Description of the Return Value
	 */
	private FontMetrics calcFontMetrics(JaText label)
	{
		return plotter.getFontMetrics(label.getFont());
	}


	private void displayTickLabelDecimal(int padX, int padY, int axis, String format)
	{
		initializeAxes();
		DecimalFormat fmt = new DecimalFormat(format);
		String[][] tLab = axes[padX - 1][padY - 1].getTicLabel();
		for (int i = 0; i < tLab[axis].length; i++)
		{
			double val = Double.valueOf(tLab[axis][i]);
			tLab[axis][i] = fmt.format(val);
		}
		axes[padX - 1][padY - 1].setTicLabel(tLab);
	}


	/**
	 *  Display the X axis tick label with a given decimal format of the pad (works
	 *  only with linear scales)
	 *
	 *@param  padX    X coordinate of the pad
	 *@param  padY    Y coordinate of the pad
	 *@param  format  The format to be used (e.g. 0.000 for displaying 3 decimals)
	 */
	public void displayTickLabelDecimalX(int padX, int padY, String format)
	{
		displayTickLabelDecimal(padX, padY, 0, format);
	}


	/**
	 *  Display the X axis tick label with a given decimal format of all the pads
	 *  (works only with linear scales)
	 *
	 *@param  format  The format to be used (e.g. 0.000 for displaying 3 decimals)
	 */
	public void displayTickLabelDecimalX(String format)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				displayTickLabelDecimalX(i + 1, j + 1, format);
			}
		}
	}


	/**
	 *  Display the Y axis tick label with a given decimal format of the pad (works
	 *  only with linear scales)
	 *
	 *@param  padX    X coordinate of the pad
	 *@param  padY    Y coordinate of the pad
	 *@param  format  The format to be used (e.g. 0.000 for displaying 3 decimals)
	 */
	public void displayTickLabelDecimalY(int padX, int padY, String format)
	{
		displayTickLabelDecimal(padX, padY, 1, format);
	}


	/**
	 *  Display the Y axis tick label with a given decimal format of all the pads
	 *  (works only with linear scales)
	 *
	 *@param  format  The format to be used (e.g. 0.000 for displaying 3 decimals)
	 */
	public void displayTickLabelDecimalY(String format)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				displayTickLabelDecimalY(i + 1, j + 1, format);
			}
		}
	}


	private void defTickLabelAxisDist(int padX, int padY, double axisDistNDC, int axis)
	{
		initializeAxes();
		axes[padX - 1][padY - 1].setLabelSpace(axis, axisDistNDC);
	}


	/**
	 *  Define the distance between the tick label and the X axis of the pad
	 *
	 *@param  padX         X coordinate of the pad
	 *@param  padY         Y coordinate of the pad
	 *@param  axisDistNDC  The distance in NDC coordinates
	 */
	public void defTickLabelAxisDistX(int padX, int padY, double axisDistNDC)
	{
		defTickLabelAxisDist(padX, padY, axisDistNDC, 0);
	}


	/**
	 *  Define the distance between the tick label and the X axis of all the pads
	 *
	 *@param  axisDistNDC  The distance in NDC coordinates
	 */
	public void defTickLabelAxisDistX(double axisDistNDC)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				defTickLabelAxisDistX(i + 1, j + 1, axisDistNDC);
			}
		}
	}


	/**
	 *  Define the distance between the tick label and the Y axis of the pad
	 *
	 *@param  padX         X coordinate of the pad
	 *@param  padY         Y coordinate of the pad
	 *@param  axisDistNDC  The distance in NDC coordinates
	 */
	public void defTickLabelAxisDistY(int padX, int padY, double axisDistNDC)
	{
		defTickLabelAxisDist(padX, padY, axisDistNDC, 1);
	}


	/**
	 *  Define the distance between the tick label and the Y axis of all the pads
	 *
	 *@param  axisDistNDC  The distance in NDC coordinates
	 */
	public void defTickLabelAxisDistY(double axisDistNDC)
	{
		for (int i = 0; i < numPadX; i++)
		{
			for (int j = 0; j < numPadY; j++)
			{
				defTickLabelAxisDistY(i + 1, j + 1, axisDistNDC);
			}
		}
	}
}

